// i.r(t), i.d(t, { default: () => SweepViewDataModule })
import {
  DisableSweepSelectionCommand,
  EnableSweepSelectionCommand,
  SweepHoverCommand,
  SweepSelectCommand,
  ToggleNonPanoCurrentPuckCommand
} from "../command/sweep.command"
import FloorsViewData from "../data/FloorsViewData"
import SweepData from "../data/SweepData"
import SweepViewData from "../data/SweepViewData"
import ViewmodeData from "../data/ViewmodeData"
import EngineContext from "../EngineContext"
import { ApplicationChangeMessage } from "../message/app.message"
import { EndMoveToFloorMessage } from "../message/floor.message"
import { TourStopAddedMessage } from "../message/tour.message"
import Module from "./Module"
export default class SweepViewDataModule extends Module {
  selectionEnabled: boolean
  nonPanoCurrentPuckVisible: boolean
  enableSweepSelection: any
  disableSweepSelection: any
  toggleCurrentPuck: any
  viewData: SweepViewData
  onSweepSelectCommand: any
  onSweepHoverCommand: any
  viewmodeData: ViewmodeData
  floorsViewData: FloorsViewData
  data: SweepData
  updateVisibility: any
  constructor() {
    super(...arguments)
    this.name = "sweep-viewdata"
    this.selectionEnabled = !0
    this.nonPanoCurrentPuckVisible = !1
    this.enableSweepSelection = async e => {
      this.selectionEnabled = !0
    }
    this.disableSweepSelection = async e => {
      this.selectionEnabled = !1
    }
    this.toggleCurrentPuck = async e => {
      this.nonPanoCurrentPuckVisible = e.visible
      this.updateVisibility(this.viewData.data.currentSweep)
    }
    this.onSweepSelectCommand = async e => {
      this.selectionEnabled && this.viewData.modifySelectAnimation(e.id, e.selected, e.duration)
    }
    this.onSweepHoverCommand = async e => {
      this.viewData.modifySelectAnimation(e.id, e.hovered, e.duration)
    }
    this.updateVisibility = async (e: any) => {
      if (this.viewmodeData.isInside()) {
        if (e) {
          const t = this.viewData.getSweep(e).neighbours
          this.viewData.iterate(e => {
            const i = this.viewData.getSweepVisibility(e) && -1 !== t.indexOf(e.id)
            this.viewData.setVisible(e.id, i)
          })
          this.viewData.setVisible(e, !1)
        }
      } else {
        this.viewData.iterate(e => {
          this.viewData.setVisible(e.id, this.floorsViewData.isCurrentOrAllFloors(e.floorId))
        })
      }
      e && this.viewData.setVisible(e, this.nonPanoCurrentPuckVisible)
    }
  }
  async init(e, t: EngineContext) {
    this.data = await t.market.waitForData(SweepData)
    this.viewData = t.market.tryGetData(SweepViewData) || new SweepViewData(this.data)
    t.market.register(this, SweepViewData, this.viewData)
    this.bindings.push(
      t.commandBinder.addBinding(SweepSelectCommand, this.onSweepSelectCommand),
      t.commandBinder.addBinding(SweepHoverCommand, this.onSweepHoverCommand),
      t.commandBinder.addBinding(EnableSweepSelectionCommand, this.enableSweepSelection),
      t.commandBinder.addBinding(DisableSweepSelectionCommand, this.disableSweepSelection),
      t.commandBinder.addBinding(ToggleNonPanoCurrentPuckCommand, this.toggleCurrentPuck),
      this.data.onChanged(() => this.viewData.updateViewData()),
      t.msgBus.subscribe(TourStopAddedMessage, () => this.viewData.updateViewData())
    )
    this.viewmodeData = await t.market.waitForData(ViewmodeData)
    this.floorsViewData = await t.market.waitForData(FloorsViewData)
    this.bindings.push(
      this.data.onPropertyChanged("currentSweep", this.updateVisibility),
      t.subscribe(EndMoveToFloorMessage, () => this.updateVisibility(this.viewData.data.currentSweep)),
      t.subscribe(ApplicationChangeMessage, () => this.updateVisibility(this.viewData.data.currentSweep)),
      this.viewmodeData.makeModeChangeSubscription(() => this.updateVisibility(this.viewData.data.currentSweep))
    )
    this.updateVisibility(this.viewData.data.currentSweep)
  }
  onUpdate(e) {
    this.viewData.updateAnimations(e)
  }
}
